package service

import (
	"center-platform/utils"
	"github.com/gin-gonic/gin"
	"path/filepath"
)

// UploadImpl ...
type UploadImpl interface {
	UploadFile(c *gin.Context) (error, string)
}

// UploadService ...
type UploadService struct {
}

// UploadFile ...
func (u *UploadService) UploadFile(c *gin.Context) (error, string) {
	file, err := c.FormFile("file")
	if err != nil {
		return err, ""
	}
	ext := filepath.Ext(file.Filename)
	path := "src/runtime/" + utils.RandomString(20) + ext

	if err = c.SaveUploadedFile(file, path); err != nil {
		return err, ""
	}
	// 删除本地文件
	//os.Remove(path)
	return nil, path
}
